/* eslint-disable max-classes-per-file */
/*
 * @Description:规则类
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2022-12-07 11:05:41
 * @LastEditors: wiz
 * @LastEditTime: 2024-04-27 15:14:22
 */
// 查询时过滤规则
export class T_qbe {
  funName: string;

  fieldName: string;

  public setFunName(p: string): T_qbe {
    this.funName = p;
    return this;
  }

  public setFieldName(p: string): T_qbe {
    this.fieldName = p;
    return this;
  }
}
export interface I_qbe extends T_qbe {}

// 统计信息
export class T_statistics {
  // 返回的别名不能与查询字段同名
  alias: string;

  // 一个bson管道表达式
  pipeline: object;

  public setAlais(p: string): T_statistics {
    this.alias = p;
    return this;
  }

  public setPipeline(p: object): T_statistics {
    this.pipeline = p;
    return this;
  }
}
export interface I_statistics extends T_statistics {}

// 规则执行

export class T_execRule {
  // 执行顺序号

  sn: number = 0;

  // 触发 before 执行前 after 执行后 undefine 无定义
  trigger: string = 'undefine';

  // 规则名
  name: string;

  // 传入参数
  inArg: Array<{ name: string; dataType: string; value: any }> = [];

  // 返回参数
  outArg: Array<{ name: string; dataType: string; value: any }> = [];

  // DB 规则执行存储过程 |General 一般软件逻辑
  type: string;

  // 不否包含事务 如果type =DB 则此项有效
  isDbTransactions: boolean;
}
export interface I_execRule extends T_execRule {}

export class T_rule {
  // qbe过滤
  QBE?: T_qbe;

  // 统计信息
  statistics?: T_statistics;

  // // 执行规则before
  // private beforeExecRule: T_execRule[] = [];

  // // 执行规则after
  // private afterExecRule: T_execRule[] = [];

  public setQBE(p: I_qbe): T_rule {
    this.QBE = p;
    return this;
  }

  public setStatistics(p: I_statistics): T_rule {
    this.statistics = p;
    return this;
  }

  // // 执行规则before
  // public setAeforeExecRule(...p: I_execRule[]) {
  //   this.beforeExecRule.push(...p);
  //   this.beforeExecRule = this.beforeExecRule.sort((a, b) => a.sn - b.sn);
  // }

  // public getBeforeExecRule(): T_execRule[] {
  //   return this.beforeExecRule;
  // }

  // // 执行规则after
  // public setAfterExecRule(...p: I_execRule[]) {
  //   this.afterExecRule.push(...p);
  //   this.afterExecRule = this.afterExecRule.sort((a, b) => a.sn - b.sn);
  // }

  // public getAfterExecRule(): T_execRule[] {
  //   return this.afterExecRule;
  // }
}
export interface I_rule extends T_rule {}
